/**
 * 
 */
package cn.softTank.BpelModelImpl;

import java.util.ArrayList;
import java.util.List;

import org.dom4j.Element;

import cn.softTank.BpelModel.Variable;
import cn.softTank.BpelModel.Variables;

/**
 * @author Yuzone (smartzxy@gmail.com)
 * 
 */
public class VariablesImpl extends ExtensibleElementImpl implements Variables {

	private List<Variable> variable;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * cn.softTank.BpelModel.Variables#addVariable(cn.softTank.BpelModel.Variable
	 * )
	 */
	@Override
	public void addVariable(Variable value) {
		if (variable == null)
			variable = new ArrayList<Variable>();
		variable.add(value);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.softTank.BpelModel.Variables#getVariable()
	 */
	@Override
	public List<Variable> getVariable() {
		return variable;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.softTank.BpelModel.Variables#removeVariableAt(int)
	 */
	@Override
	public void removeVariableAt(int index) {
		if (variable != null && index < variable.size())
			variable.remove(index);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.softTank.BpelModel.Variables#setVariable(java.util.List)
	 */
	@Override
	public void setVariable(List<Variable> value) {
		variable = value;
	}

	@Override
	public Element toElement() {
		node = super.toElement();
		node.setName("variables");
		if (variable != null)
			for (int i = 0; i < variable.size(); i++)
				node.add(variable.get(i).toElement());
		return node;
	}

}
